package com.zpb.admin.controller;

import com.zpb.admin.domain.entity.AdminUserInfoVo;
import com.zpb.framework.annotation.SysLog;
import com.zpb.framework.domain.ApiResult;
import com.zpb.framework.domain.enums.ResultCodeEnum;
import com.zpb.framework.domain.vo.LoginVo;
import com.zpb.framework.exception.SystemException;
import com.zpb.admin.service.AdminLoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description:
 * @Author: zhaopengbo
 * @Date: 2025/9/18
 */
@RestController
@Slf4j
public class AdminLoginController {
    @Autowired
    private AdminLoginService adminLoginService;
    @PostMapping("/user/login")
    public ApiResult<Map<String,Object>> login(@RequestBody LoginVo user) {
        if (!StringUtils.hasText(user.getUsername())){
            throw new SystemException(ResultCodeEnum.NO_USERNAME);
        }
        if (!StringUtils.hasText(user.getPassword())){
            throw new SystemException(ResultCodeEnum.NO_PASSWORD);
        }
        return adminLoginService.login(user);
    }
    @SysLog(businessName = "获取信息")
    @GetMapping("/getInfo")
    public ApiResult<AdminUserInfoVo> getInfo(){

        return adminLoginService.getInfo();
    }
    @GetMapping("/getRouters")
    public ApiResult<Map<String,Object>> getRouters(){
        return adminLoginService.getRouters();
    }
    @RequestMapping("/user/logout")
    public ApiResult logout() {
        return adminLoginService.logout();
    }
}
